package com.iyoyi.skinlib.widget;

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;

public class ImageViewFactory extends AbstractViewFactory<AppCompatImageView> {
    private static ImageViewFactory sInst;

    private ImageViewFactory() {/**/}

    public static ImageViewFactory get() {
        synchronized (ImageViewFactory.class) {
            if (sInst == null) {
                sInst = new ImageViewFactory();
            }
        }
        return sInst;
    }

    @NonNull
    public static AppCompatImageView createImageView(Context context, AttributeSet attrs) {
        return new AppCompatImageView(context, attrs);
    }


    @Override
    void onAttributeUpdate(AppCompatImageView view, Resources resources, String name, int id) {
        switch (name) {
            case "src":
            case "srcCompat":
                view.setImageDrawable(ContextCompat.getDrawable(view.getContext(), id));
                break;
        }
    }
}
